import 'package:dio/dio.dart';
import 'package:hello/service/config.dart';

class HttpRequest {
  static final BaseOptions baseOptions = BaseOptions(
      baseUrl: HttpConfig.baseUrl,
      connectTimeout: HttpConfig.connectTimeout
  );
  static final Dio dio = Dio(baseOptions);

  static Future<T> request<T>(String url,{ String method = "GET",Map<String, dynamic> params }) async {
  //  创建单独配置
    final options = Options(method: method);
    try{
      Response response = await dio.request(url,queryParameters: params,options: options);
      return response.data;
    }on DioError catch(e){
        return Future.error(e);
    }

  }
}